unit MenuItemWidget;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
  Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.Buttons, MenuButton,
  Vcl.Imaging.pngimage;

type
  TfrMenuItem = class(TFrame)
    pnItembutton: TPanel;
    imagedown: TImage;
    Button: TLabel;
    pnButton: TPanel;
    image: TImage;
    imageup: TImage;
    procedure ButtonMouseEnter(Sender: TObject);
    procedure ButtonMouseLeave(Sender: TObject);
    procedure ButtonClick(Sender: TObject);
  private
    pnBtnheight: Integer;
    const
      m = $00453426;
    const
      m1 = $00564120;
    const
      m2 = $00564140;

    { Private declarations }
    procedure setimage;
    procedure setState;
  public
    { Public declarations }
    procedure init;
    function addButton: TfrMenuButton;
    constructor Create(AOwner: TComponent); override;
  end;

implementation

uses
  MsgWidget;

{$R *.dfm}

function TfrMenuItem.addButton: TfrMenuButton;
var
  menubutton: TfrMenuButton;
begin
  menubutton := TfrMenuButton.Create(Self);
  menubutton.Parent := pnButton;
  menubutton.Align := alTop;
  pnBtnheight := pnBtnheight + menubutton.Height + 1;
  pnButton.Height := pnBtnheight;
  Result := menubutton;
end;

constructor TfrMenuItem.Create(AOwner: TComponent);
begin
  inherited;
  init;
end;

procedure TfrMenuItem.init;
begin

  pnButton.Visible := false;
  self.Height := pnItembutton.Height;
  setimage;
end;

procedure TfrMenuItem.setState;
begin
  self.pnButton.Visible := not self.pnButton.Visible;

  if self.pnButton.Visible then
  begin

    self.Height := pnBtnheight + self.pnItembutton.Height + 1;
  end
  else
  begin
    self.Height := self.pnItembutton.Height;
  end;
  setimage;
end;

procedure TfrMenuItem.ButtonClick(Sender: TObject);
begin

  SendMessage(self.Parent.Parent.Handle, WM_CLOSEITEM_MSG, 0, Integer(PChar(self.Name)));
  TThread.CreateAnonymousThread(
    procedure
    begin
      sleep(100);
      TThread.Synchronize(TThread.CurrentThread,
        procedure
        begin
          setState;
        end);
    end).Start;
end;

procedure TfrMenuItem.ButtonMouseEnter(Sender: TObject);
begin
 // Label1.Font.Color := clBlue;
  self.Color := m;
end;

procedure TfrMenuItem.ButtonMouseLeave(Sender: TObject);
begin
 // Label1.Font.Color := clWhite;
  Self.Color := m1;
end;

procedure TfrMenuItem.setimage;
begin
  imagedown.Visible := not pnButton.Visible;
  imageup.Visible := not imagedown.Visible;
end;

end.

